using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VSRCIND
    {
        public DataRow Convert2SRCIND(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QuerySRCIND(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["SRCKEY"] = " ".PadRight(0 ); 
         dwReturn["SRCNAME"] = " ".PadRight(20 ); 
         dwReturn["SRCTYP"] = " ".PadRight(1 ); 
         dwReturn["SRCSTYP"] = " ".PadRight(1 ); 
         dwReturn["SRCVB"] = " ".PadRight(2 ); 
         dwReturn["SRCOP1"] = " ".PadRight(1 ); 
         dwReturn["SRCOP2"] = " ".PadRight(1 ); 
         dwReturn["SRCOP3"] = " ".PadRight(1 ); 
         dwReturn["SRCOP4"] = " ".PadRight(1 ); 
         dwReturn["SRCDBKEY1"] = " ".PadRight(3 ); 
         dwReturn["SRCDBKEY2"] = " ".PadRight(3 ); 
         dwReturn["SRCDBKEY3"] = " ".PadRight(3 ); 
         dwReturn["SRCDBKEY4"] = " ".PadRight(3 ); 
         dwReturn["SRCDBKEY5"] = " ".PadRight(3 ); 
         dwReturn["SRCDBKEY6"] = " ".PadRight(3 ); 
         dwReturn["SRCDBKEY7"] = " ".PadRight(3 ); 
         dwReturn["SRCDBKEY8"] = " ".PadRight(3 ); 
         dwReturn["SRCDBKEY9"] = " ".PadRight(3 ); 
         dwReturn["SRCDBKEY10"] = " ".PadRight(3 ); 
         dwReturn["SRCSTEXT"] = " ".PadRight(100 ); 
         dwReturn["SRCRKEY"] = " ".PadRight(0 ); 
         dwReturn["SRCSDDAT"] = " ".PadRight(1 ); 
         dwReturn["SRCNEUDAT"] = " ".PadRight(10 ); 
         dwReturn["SRCFILLER"] = " ".PadRight(123 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapSRCIND(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveSRCIND(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QuerySRCIND(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapSRCIND(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertSRCIND(dwLocal, ITXDBVERSION);
            }
            UpdateSRCIND(dwLocal);
        }
        public void InsertSRCIND(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO SRCIND(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QuerySRCIND(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM SRCIND WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM SRCIND  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "SRCIND";
            Return = Result;
            return Return;
        }
        public void DeleteSRCIND(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM SRCIND   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateSRCIND(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE SRCIND SET "
                    +"SRCKEY= :SRCKEY,"
                    +"SRCNAME= :SRCNAME,"
                    +"SRCTYP= :SRCTYP,"
                    +"SRCSTYP= :SRCSTYP,"
                    +"SRCVB= :SRCVB,"
                    +"SRCOP1= :SRCOP1,"
                    +"SRCOP2= :SRCOP2,"
                    +"SRCOP3= :SRCOP3,"
                    +"SRCOP4= :SRCOP4,"
                    +"SRCDBKEY1= :SRCDBKEY1,"
                    +"SRCDBKEY2= :SRCDBKEY2,"
                    +"SRCDBKEY3= :SRCDBKEY3,"
                    +"SRCDBKEY4= :SRCDBKEY4,"
                    +"SRCDBKEY5= :SRCDBKEY5,"
                    +"SRCDBKEY6= :SRCDBKEY6,"
                    +"SRCDBKEY7= :SRCDBKEY7,"
                    +"SRCDBKEY8= :SRCDBKEY8,"
                    +"SRCDBKEY9= :SRCDBKEY9,"
                    +"SRCDBKEY10= :SRCDBKEY10,"
                    +"SRCSTEXT= :SRCSTEXT,"
                    +"SRCRKEY= :SRCRKEY,"
                    +"SRCSDDAT= :SRCSDDAT,"
                    +"SRCNEUDAT= :SRCNEUDAT,"
                    +"SRCFILLER= :SRCFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("SRCKEY", OracleType.NVarChar).Value = dwData["SRCKEY"].ToString(); 
          or1.Parameters.Add("SRCNAME", OracleType.NVarChar).Value = dwData["SRCNAME"].ToString(); 
          or1.Parameters.Add("SRCTYP", OracleType.NVarChar).Value = dwData["SRCTYP"].ToString(); 
          or1.Parameters.Add("SRCSTYP", OracleType.NVarChar).Value = dwData["SRCSTYP"].ToString(); 
          or1.Parameters.Add("SRCVB", OracleType.NVarChar).Value = dwData["SRCVB"].ToString(); 
          or1.Parameters.Add("SRCOP1", OracleType.NVarChar).Value = dwData["SRCOP1"].ToString(); 
          or1.Parameters.Add("SRCOP2", OracleType.NVarChar).Value = dwData["SRCOP2"].ToString(); 
          or1.Parameters.Add("SRCOP3", OracleType.NVarChar).Value = dwData["SRCOP3"].ToString(); 
          or1.Parameters.Add("SRCOP4", OracleType.NVarChar).Value = dwData["SRCOP4"].ToString(); 
          or1.Parameters.Add("SRCDBKEY1", OracleType.NVarChar).Value = dwData["SRCDBKEY1"].ToString(); 
          or1.Parameters.Add("SRCDBKEY2", OracleType.NVarChar).Value = dwData["SRCDBKEY2"].ToString(); 
          or1.Parameters.Add("SRCDBKEY3", OracleType.NVarChar).Value = dwData["SRCDBKEY3"].ToString(); 
          or1.Parameters.Add("SRCDBKEY4", OracleType.NVarChar).Value = dwData["SRCDBKEY4"].ToString(); 
          or1.Parameters.Add("SRCDBKEY5", OracleType.NVarChar).Value = dwData["SRCDBKEY5"].ToString(); 
          or1.Parameters.Add("SRCDBKEY6", OracleType.NVarChar).Value = dwData["SRCDBKEY6"].ToString(); 
          or1.Parameters.Add("SRCDBKEY7", OracleType.NVarChar).Value = dwData["SRCDBKEY7"].ToString(); 
          or1.Parameters.Add("SRCDBKEY8", OracleType.NVarChar).Value = dwData["SRCDBKEY8"].ToString(); 
          or1.Parameters.Add("SRCDBKEY9", OracleType.NVarChar).Value = dwData["SRCDBKEY9"].ToString(); 
          or1.Parameters.Add("SRCDBKEY10", OracleType.NVarChar).Value = dwData["SRCDBKEY10"].ToString(); 
          or1.Parameters.Add("SRCSTEXT", OracleType.NVarChar).Value = dwData["SRCSTEXT"].ToString(); 
          or1.Parameters.Add("SRCRKEY", OracleType.NVarChar).Value = dwData["SRCRKEY"].ToString(); 
          or1.Parameters.Add("SRCSDDAT", OracleType.NVarChar).Value = dwData["SRCSDDAT"].ToString(); 
          or1.Parameters.Add("SRCNEUDAT", OracleType.NVarChar).Value = dwData["SRCNEUDAT"].ToString(); 
          or1.Parameters.Add("SRCFILLER", OracleType.NVarChar).Value = dwData["SRCFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
